package com.example.fragmenttest203jr.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.fragmenttest203jr.R;
import com.example.fragmenttest203jr.adapter.MyAdapter;
import com.example.fragmenttest203jr.bean.ArticleBean;
import com.example.fragmenttest203jr.iface.ArticleListener;
import com.example.fragmenttest203jr.model.ArticleModel;

import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class WeixinFragment extends Fragment implements ArticleListener{
    private View view;
    private Context context;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    MyAdapter myAdapter;
    List<ArticleBean>list=null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getActivity();
        view =inflater.inflate(R.layout.wfragment,container,false);
        recyclerView=(RecyclerView)view.findViewById(R.id.wrecylerview);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);

        myAdapter=new MyAdapter(context);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);

        ArticleModel articleModol=new ArticleModel();
        articleModol.getResultLIist("article",2,
                "2ts2j910hv4m270hipde4a67d7",this);
       // Toast.makeText(context, "加载文章", Toast.LENGTH_SHORT).show();


        return view;
    }

    @Override
    public void onResponse(List<ArticleBean> list) {
        list=list;
        myAdapter.setList(list);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
}
